package com.ktwlsoft.archivemanage.controller.sms;

import com.ktwlsoft.archivemanage.domain.business.businessService.VerificationCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 验证码控制器
 *
 * @author zhuhe on 2019/5/17 11:21
 * @version 1.0
 */
@Api(value = "验证码控制器", description = "验证码控制器")
@RestController
@RequestMapping("verificationCode")
@RequiredArgsConstructor
public class VerificationCodeController {

    private final VerificationCodeService service;

    /**
     * 获取手机验证码 on 2019/5/17 11:25
     *
     * @return ResponseEntity<Object>
     */
    @ApiOperation(value = "获取手机验证码", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "getPhoneVerificationCode")
    public ResponseEntity<?> getVerificationCode(@ApiParam(value = "手机号", name = "phone") @RequestParam(defaultValue = "") String phone,
                                                 @ApiParam(value = "标识", name = "id") @RequestParam(defaultValue = "") String id) {
        return service.getVerificationCode(phone, id);
    }

    /**
     * 获取验证码图片 on 2020/4/8 12:08
     *
     * @param response response
     * @param request  request
     */
    @ApiOperation(value = "获取验证码图片", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @GetMapping(value = "getVerifyCode")
    public void getVerificationCode(HttpServletResponse response, HttpServletRequest request, @RequestParam Long id) {
        service.getVerificationCode(response,request,id);
    }

    /**
     * 检查验证码 on 2019/5/17 11:25
     *
     * @return ResponseEntity<Object>
     */
    @ApiOperation(value = "检查验证码", httpMethod = "GET", produces = "application/json", response = ResponseEntity.class)
    @ResponseBody
    @GetMapping(value = "inspectVerificationCode")
    public ResponseEntity<Object> inspectVerificationCode(@ApiParam(value = "验证码", name = "code") @RequestParam(defaultValue = "") String code,
                                                          @ApiParam(value = "标识", name = "id") @RequestParam(defaultValue = "") String id) {
        return service.inspectVerificationCode(code, id);
    }
}